<!DOCTYPE html>
<html>
<head>
	<title>纸币找零</title>
</head>
<body>

<script type="text/javascript">
//假设1元、2元、5元、10元、20元、50元、100元的纸币，张数不限制，现在要用来支付K元，至少要多少张纸币？
function minCoinChange (money, k) {
	let n = k;
	let obj = {};
	let totalNum = 0;

	money.forEach((item) => {
		let num1 = parseInt(n / item);
		//如果能使用当前币值
		if(num1) {
			obj[item] = num1;
			totalNum += num1;
			n = n - (num1 * item);
		}
	})
	console.log(obj);
	console.log(totalNum);
	return obj;
}
minCoinChange([100, 50, 20, 10, 5, 2, 1], 352);
minCoinChange([11, 5, 1], 15);// 使用3张5元才是最优解
</script>
</body>
</html>